jun.KasMasukGrid = Ext.extend(Ext.grid.GridPanel, {
    title: "Daftar Kas Masuk",
    id: 'docs-jun.KasMasukGrid',
    iconCls: 'silk-grid',
    viewConfig: {
        forceFit: true,
    },
    sm: new Ext.grid.RowSelectionModel({
        singleSelect: true
    }),
    columns: [{
        header: 'Ref. Dokumen',
        sortable: true,
        resizable: true,
        dataIndex: 'doc_ref',
        width: 100
    }, {
        header: 'No. Bukti',
        sortable: true,
        resizable: true,
        dataIndex: 'no_bukti',
        width: 100
    }, {
        header: 'Total',
        sortable: true,
        resizable: true,
        dataIndex: 'amount',
        width: 100
    }, {
        header: 'Tanggal Transaksi',
        sortable: true,
        resizable: true,
        dataIndex: 'trans_date',
        width: 100
    },
    /*
         {
         header:'trans_via',
         sortable:true,
         resizable:true,                        
         dataIndex:'trans_via',
         width:100
         },
         {
         header:'note',
         sortable:true,
         resizable:true,                        
         dataIndex:'note',
         width:100
         },
         {
         header:'id_bank',
         sortable:true,
         resizable:true,                        
         dataIndex:'id_bank',
         width:100
         },
         {
         header:'id_kavling',
         sortable:true,
         resizable:true,                        
         dataIndex:'id_kavling',
         width:100
         },
         */

    ],
    initComponent: function() {
        this.store = jun.rztKasMasuk;
        //        this.bbar = {
        //            items: [
        //           {
        //            xtype: 'paging',
        //            store: this.store,
        //            displayInfo: true,
        //            pageSize: 10
        //           }]
        //        };
        this.tbar = {
            xtype: 'toolbar',
            items: [{
                xtype: 'button',
                text: 'Tambah Kas Masuk',
                ref: '../btnAdd'
            }, {
                xtype: 'tbseparator',
            }, {
                xtype: 'button',
                text: 'Lihat Kas Masuk',
                ref: '../btnEdit'
            }, {
                xtype: 'tbseparator',
            }, {
                xtype: 'button',
                text: 'Void Kas Masuk',
                ref: '../btnDelete'
            }]
        };
        jun.rztBank.reload();
        jun.rztKavling.reload();
        jun.rztKasMasuk.reload();
        jun.KasMasukGrid.superclass.initComponent.call(this);
        this.btnAdd.on('Click', this.loadForm, this);
        this.btnEdit.on('Click', this.loadEditForm, this);
        this.btnDelete.on('Click', this.deleteRec, this);
        this.getSelectionModel().on('rowselect', this.getrow, this);
    },
    getrow: function(sm, idx, r) {
        this.record = r;

        var selectedz = this.sm.getSelections();
    },
    loadForm: function() {
        var form = new jun.KasMasukWin({
            modez: 0
        });
        form.show();
    },
    loadEditForm: function() {
        var selectedz = this.sm.getSelected();
        if (selectedz == "") {
            Ext.MessageBox.alert("Warning", "Anda belum memilih kas masuk");
            return;
        }
        var idz = selectedz.json.kas_masuk_id;
        Ext.Ajax.request({
            url: 'KasMasuk/view',
            params: {
                id: idz,
            },
            method: 'POST',
            success: function(f, a) {
                var response = Ext.decode(f.responseText);
                if (response.success == false) {
                    Ext.MessageBox.show({
                        title: 'Warning',
                        msg: response.msg,
                        buttons: Ext.MessageBox.OK,
                        icon: Ext.MessageBox.WARNING
                    });
                    return;
                }
                //                this.show();
                var data = response.results[0];
                var form = new jun.KasMasukShowWin({
                    modez: 1,
                    id: idz
                });
                form.txtRef.text = data.doc_ref;
                form.trans_entry.text = data.entry_time;
                form.no_bukti.text = data.no_bukti;
                form.trans_date.text = data.trans_date;
                form.kas.text = data.bank;
                form.kavling.text = data.kavling;
                form.amount.text = Ext.util.Format.number(data.amount, '0,0');
                form.trans_via.text = data.trans_via;
                form.note.text = data.note;
                form.show(this);
            },
            failure: function(f, a) {
                Ext.MessageBox.alert("Error", "Can't Communicate With The Server");
            }
        });
    },
    deleteRec: function() {
        Ext.MessageBox.confirm('Pertanyaan', 'Apakah anda yakin ingin void data ini?', this.deleteRecYes, this);
    },
    deleteRecYes: function(btn) {

        if (btn == 'no') {
            return;
        }

        var record = this.sm.getSelected();

        // Check is list selected
        if (record == "") {
            Ext.MessageBox.alert("Warning", "Anda Belum Memilih Data");
            return;
        }
        var idz = record.json.kas_masuk_id;
        var form = new jun.KasMasukVoidWin({
            id: idz
        });
        form.show(this);



    }
})